﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Kooboo.IoC;
using Kooboo.Domain;

namespace Kooboo.Commerce.Repositories
{
    public abstract class EntityDeleteCommand<TEntity> : IEntityDeleteCommand<TEntity>
    {

        protected abstract string TableName
        {
            get;
        }

        protected abstract string BuildCondition();

        #region IEntityDeleteCommand<TEntity> Members

        public IQueryable<TEntity> EntitySet
        {
            get;
            set;
        }

        #endregion

        #region IEntityCommand Members

        public virtual void Execute()
        {
           var commandText =  string.Format("DELETE FROM [{0}] WHERE {1}", this.TableName,this.BuildCondition());

           var context = ContextContainer.Current.Resolve<DataWriterContext>();
           context.ExecuteCommand(commandText);
        }

        #endregion
    }
}
